/*
 This file 'AjaxException' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2014 Lincong

 Contact:  
 Email: lincong1987@gmail.com

 QQ: 159257119

 See Usage at http://www.jplatformx.com/firebird

 Create date: 2014-08-13 14:09
 */

define(function (require, exports, module) {

	require("Firebird.lang.Exception");
	require("Firebird.ui.Dialog");
	require("Firebird.ui.TextArea");

	/**
	 * Firebird.lang.AjaxException
	 * @class Firebird.lang.AjaxException
	 */
	Firebird.define("Firebird.lang.AjaxException", {
		extend: "Firebird.lang.Exception",
		statics: {
			_uuid: 1,
			uuid: function (prefix) {
				return (prefix || "") + this._uuid++;
			}
		},
		config: {
			code: null,
			message: null,
			stack: null
		},
		_init: function () {
			var e = new Error();
			e.name = "Firebird.lang.Exception";
			e.message = this.getMessage() || "系统异常";
			e.stack = this.getStack() || e.stack || "UNKNOW ERROR";
			e.code = this.getCode() || "001";
			firebird.error(e);

			if (fb.devMode == true) {
				var uuid = Firebird.lang.AjaxException.uuid("ajaxexception_");
				var $textarea = $(Firebird.Tmpl.compile("<textarea fb-ui='textArea' name='{{uuid}}'>{{message}}</textarea>")({
					uuid: uuid,
					message: (this.getMessage().length > 50 ? this.getMessage() : "") + this.getStack()
				}));
				Firebird.ui.Dialog.error($textarea,
					null,
					{
						title: this.getMessage().substring(0, 20),
						width: 500
					});
				Firebird.create("Firebird.ui.TextArea", {
					renderTo: $textarea,
					width: 390,
					height: 160,
					disabled: true
				});
			} else {
				var uuid = Firebird.lang.AjaxException.uuid("ajaxexception_");
				var $textarea = $(Firebird.Tmpl.compile("<textarea fb-ui='textArea' name='{{uuid}}'>{{message}}</textarea>")({
					uuid: uuid,
					message: (this.getMessage().length > 50 ? this.getMessage() : "") + this.getStack()
				}));
				Firebird.ui.Dialog.error($textarea,
					null,
					{
						title: this.getMessage().substring(0, 20),
						width: 500
					});
				Firebird.create("Firebird.ui.TextArea", {
					renderTo: $textarea,
					width: 390,
					height: 160,
					disabled: true
				});
			}

		}
	});

	module.exports = Firebird.lang.AjaxException;

});